#!/usr/bin/env python
#
#       Dialogs.py
#       
#       Copyright 2009 Brandon Invergo <brandon@brandoninvergo.com>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

import sys
import locale

try:
    import pygtk
    #tell pyGTK, if possible, that we want GTKv2
    pygtk.require("2.0")
except:
    #Some distributions come with GTK2, but not pyGTK
    pass

try:
    import gtk
    import gtk.glade
    
except:
    print "You need to install pyGTK or GTKv2 ",
    print "or set your PYTHONPATH correctly."
    print "try: export PYTHONPATH=",
    print "/usr/local/lib/python2.2/site-packages/"
    sys.exit(1)
        
class Error_dialog:
    def show_error(self, primary_string, secondary_string):
        if type(secondary_string) == type(list()):
            secondary_string = self.lines_to_full(secondary_string)
        primary_markup = ["<b>", primary_string, "</b>"]
        primary_markup_string = ''.join(primary_markup)
        self.dialog.set_markup(primary_markup_string)
        self.dialog.format_secondary_text(secondary_string)
        self.dialog.run()
        
    def lines_to_full(self, message_str):
        full_str = ""
        for line in message_str:
            full_str = full_str + line
        return full_str
        
    def on_response(self, widget, response):
        self.dialog.hide()
        
    def __init__(self):
        gladefile = "Error_dialog.glade"
        self.glade_gui = gtk.glade.XML(gladefile)
        self.dialog = self.glade_gui.get_widget("Error_dialog")
        
        callbacks = {"on_error_dialog_response" : self.on_response}
        
        self.glade_gui.signal_autoconnect(callbacks)
